package com.wb.spring.boot.autoconfigure.load;

import org.apache.commons.lang3.math.NumberUtils;

import java.util.List;

/**
 * 轮询(默认实现服务负载均衡)
 *
 * @Author deeprado
 * @Date 2022/9/14 11:12
 */
public class PollingLoad implements Load {

    private Integer index = NumberUtils.INTEGER_ZERO;

    @Override
    public String load(List<String> servers) {
        index = (index + 1) >= servers.size() ? NumberUtils.INTEGER_ZERO : index + 1;
        return servers.get(index);
    }
}
